<?php
/**
 * Copyright (c) 2012-2013 Aalto University and University of Helsinki
 * MIT License
 * see LICENSE.txt for more information
 */

/**
 * Use Composer autoloader to automatically load library classes.
 */
try {
  if (!file_exists('./vendor/autoload.php'))
    throw new Exception( 'Dependencies managed by composer missing. Please run "php composer.phar install".', 0, $e);
  require_once('vendor/autoload.php');
} catch(Exception $e) {
  echo "Error: " . $e->getMessage();
}

require_once("model/Model.php");

/**
 * Handles all the requests from the user and changes the view accordingly. 
 */
class Controller {
  /**
   * The controller has to know the model to access the data stored there.
   * @param $model contains the Model object.
   */
  public $model;

  protected $negotiator;
  
  /**
   * Initializes the Model object.
   */
  public function __construct() {
    $this->model = new Model();
    $this->negotiator = new \Negotiation\FormatNegotiator();
  }

  /**
   * Sets the locale language properties from the parameter (used by gettext and some Model classes).
   * @param string $lang language parameter eg. 'fi' for Finnish.
   */
  public function setLanguageProperties($lang) {
    if ($lang == 'fi') {
      // Set language to finnish
      putenv('LC_ALL=fi_FI.utf8');
      setlocale(LC_ALL, 'fi_FI.utf8');
    } else if ($lang == 'sv') {
      // Set language to swedish
      putenv('LC_ALL=sv_SE.utf8');
      setlocale(LC_ALL, 'sv_SE.utf8');
    } else if ($lang == 'en') {
      // Set language to english
      putenv('LC_ALL=en_GB.utf8');
      setlocale(LC_ALL, 'en_GB.utf8');
    } else {
      trigger_error("Unsupported language '$lang', not setting locale", E_USER_WARNING);
    }
  }
  
}

?>
